import { MessageDto } from "../../../structures/dto/Message";
import { Payload } from "../../../structures/dto/Payload";
import { Client } from "../../Client";

/*

    {
        "t":"MESSAGE_UPDATE",
        "s":3,
        "op":0,
        "d":{
            "type":0,
            "tts":false,
            "timestamp":"2023-11-19T17:26:39.048000+00:00",
            "pinned":false,
            "mentions":[],
            "mention_roles":[],
            "mention_everyone":false,
            "member":{
                "roles":[
                    "302181071959752704",
                    "302183276699713536"
                ],
                "premium_since":null,
                "pending":false,
                "nick":null,
                "mute":false,
                "joined_at":"2016-01-12T20:06:43.794000+00:00",
                "flags":0,
                "deaf":false,
                "communication_disabled_until":null,
                "avatar":null
            },
            "id":"1175849634304901260",
            "flags":0,
            "embeds":[],
            "edited_timestamp":"2023-11-19T17:30:00.051349+00:00",
            "content":"gh 212 3123",
            "components":[],
            "channel_id":"595032489530097846",
            "author":{
                "username":"timosh",
                "public_flags":0,
                "premium_type":0,
                "id":"118483467766857735",
                "global_name":"Timosh",
                "discriminator":"0",
                "avatar_decoration_data":null,
                "avatar":"643fbd518376a074858bcf41a1c36751"
            },
            "attachments":[],
            "guild_id":"136561520980000768"
        }
    }


    {
        "t":"MESSAGE_UPDATE",
        "s":51,
        "op":0,
        "d":{
            "type":0,
            "tts":false,
            "timestamp":"2023-11-19T17:35:45.534000+00:00",
            "position":3,
            "pinned":false,
            "mentions":[],
            "mention_roles":[],
            "mention_everyone":false,
            "member":{
                "roles":[],
                "premium_since":null,
                "pending":false,
                "nick":null,
                "mute":false,
                "joined_at":"2023-11-19T17:20:01.271000+00:00",
                "flags":0,
                "deaf":false,
                "communication_disabled_until":null,
                "avatar":null
            },
            "id":"1175851926433308833",
            "flags":0,
            "embeds":[],
            "edited_timestamp":"2023-11-19T17:35:49.928926+00:00",
            "content":"oh, okay. ill figure out how to update it then",
            "components":[],
            "channel_id":"1175850453637009518",
            "author":{
                "username":"maddogslayer",
                "public_flags":0,
                "premium_type":0,
                "id":"504052238952693783",
                "global_name":"Matty",
                "discriminator":"0",
                "avatar_decoration_data":null,
                "avatar":"dcaf1afd8c528c2a899b096c16a9eec6"
            },
            "attachments":[],
            "guild_id":"745037351163527189"
        }
    }


    {
        "t":"MESSAGE_UPDATE",
        "s":62,
        "op":0,
        "d":{
            "id":"1175853404740923462",
            "embeds":[
                {
                    "url":"https://github.com/WeakAuras/LibRangeCheck-3.0/pull/4",
                    "type":"article",
                    "title":"fix min-range checker by mitchnull · Pull Request #4 · WeakAuras/Li...",
                    "thumbnail":{
                        "width":1200,
                        "url":"https://opengraph.githubassets.com/853d68f1a7d3862520b109949f4072022fa776742ceecb23d2b8cfc5fafc0762/WeakAuras/LibRangeCheck-3.0/pull/4",
                        "proxy_url":"https://images-ext-1.discordapp.net/external/H4abPWXDNTVL0K7WCbRzUTMFp0OTji_THiVqVPpceyk/https/opengraph.githubassets.com/853d68f1a7d3862520b109949f4072022fa776742ceecb23d2b8cfc5fafc0762/WeakAuras/LibRangeCheck-3.0/pull/4",
                        "height":600
                    },
                    "provider":{
                        "name":"GitHub"
                    },
                    "description":"We should use a spell for min-range checking that has a minRange of 0 and has a range between the original spell's minRange and range. If no such spell exists, we should not use the spell with ...",
                    "content_scan_version":1,
                    "color":1975079
                }
            ],
            "channel_id":"854475151311503411",
            "guild_id":"327414731654692866"
        }
    }


    {
        "t":"MESSAGE_UPDATE",
        "s":3,
        "op":0,
        "d":{
            "id":"1180673447014178896",
            "embeds":[
                {
                    "url":"https://stackoverflow.com/questions/53135155/how-to-set-textfields-underline-color",
                    "type":"link",
                    "title":"How to set TextField's underline color?",
                    "thumbnail":{
                        "width":316,
                        "url":"https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon@2.png?v=73d79a89bded",
                        "proxy_url":"https://images-ext-1.discordapp.net/external/VbfwnzN2MM794XNccNxDzrB1YeuPrxR53y11bwRfflY/%3Fv%3D73d79a89bded/https/cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon%402.png",
                        "height":316
                    },
                    "provider":{
                        "name":"Stack Overflow"
                    },
                    "description":"How do you set the color of the line in TextField to another color?\n\nWith Material theme you can change \"Material.accent\" color, but I want to change the permanent color, not only when the line gets"
                }
            ],
            "channel_id":"1176621666923712669"
        }
    }

    {
        "t":"MESSAGE_UPDATE",
        "s":4,
        "op":0,
        "d":{
            "type":0,
            "tts":false,
            "timestamp":"2023-12-03T00:54:45.620000+00:00",
            "pinned":false,
            "mentions":[],
            "mention_roles":[],
            "mention_everyone":false,
            "id":"1180673447014178896",
            "flags":0,
            "embeds":[],
            "edited_timestamp":"2023-12-03T00:59:25.948385+00:00",
            "content":"WOpp WOop",
            "components":[],
            "channel_id":"1176621666923712669",
            "author":{
                "username":"timosh",
                "public_flags":0,
                "premium_type":0,
                "id":"118483467766857735",
                "global_name":"Timosh",
                "discriminator":"0",
                "avatar_decoration_data":null,
                "avatar":"643fbd518376a074858bcf41a1c36751"
            },
            "attachments":[]
        }
    }

    {
        "t": "MESSAGE_UPDATE",
        "s": 22,
        "op": 0,
        "d": {
            "id": "1182801852597797005",
            "embeds": [
                {
                    "video": {
                        "width": 640,
                        "url": "https://media.tenor.com/aZMOFP1N5TEAAAPo/angry-cat-triggered.mp4",
                        "proxy_url": "https://images-ext-2.discordapp.net/external/1QR-R1Q3ohjhpw8kIYq4Kk03VfuFmT5IE0Ut48LsWgA/https/media.tenor.com/aZMOFP1N5TEAAAPo/angry-cat-triggered.mp4",
                        "height": 390
                    },
                    "url": "https://tenor.com/view/angry-cat-triggered-ahhh-meeeeoow-gif-16764869",
                    "type": "gifv",
                    "thumbnail": {
                        "width": 640,
                        "url": "https://media.tenor.com/aZMOFP1N5TEAAAAe/angry-cat-triggered.png",
                        "proxy_url": "https://images-ext-2.discordapp.net/external/3sy7jujtyv8q0t3FPZAs9JFZO2DvtdySN2PEqfAdQcQ/https/media.tenor.com/aZMOFP1N5TEAAAAe/angry-cat-triggered.png",
                        "height": 390
                    },
                    "provider": {
                        "url": "https://tenor.co",
                        "name": "Tenor"
                    }
                }
            ],
            "channel_id": "1176621666923712669"
        }
    }
*/

export function MESSAGE_UPDATE(client: Client, payload: Payload<MessageDto>) {

    const { d: data } = payload

    // console.log("MESSAGE_UPDATE " + JSON.stringify(payload))
    
    if (!data) return;

    // console.log("Message update " + 
    //     "id=" + data.id + ", " +
    //     "channel_id=" + data.channel_id + ", " +
    //     "guild_id=" + data.guild_id + ", " +
    //     "content=" + data.content + ", " + 
    //     "author=" + data.author.username + "(" + data.author.global_name + ")" 
    // )

    // client.messages[data.id] = data

    // client.emit("message", data);
}